﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Tmkilla.Localizr.Web.Base.Mvc.General;

namespace Tmkilla.Localizr.Web.Base.Mvc.Controllers
{
    public class ControllerBase : Controller, IControllerBase
    {
        #region Constructor

        public ControllerBase()
        {
            ViewBag.ThemeUrl = string.Format("~/Content/Themes/{0}/", Config.Configuration.Theme);
        }

        #endregion

        #region Private methods

        protected bool PrepareCommonViewData()
        {
            // CMS Settings
            if (!PrepareCmsViewData())
            {
                return false;
            }

            // Data
            PrepareDataViewData();

            return true;
        }

        protected bool PrepareCmsViewData()
        {
            ViewBag.AjaxLoadingMessage = string.Format("<img src=\"{0}\" alt=\"Loading ...\" class=\"ajax-loader\" />", Url.Content(ViewBag.ThemeUrl + "Images/ajax-loader.gif"));

            return true;
        }

        protected virtual void PrepareDataViewData()
        {
        }

        protected virtual void SetNavigationPath(IEnumerable<NavigationPathItem> items = null)
        {
        }

        protected void SetFormActionResult(bool isError, string message)
        {
            ViewBag.HasFormActionResult = true;
            ViewBag.FormActionResultIsError = isError;
            ViewBag.FormActionResultMessage = message;
        }

        #endregion
    }
}
